package com.ss.android.article.base.feature.detail.view;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.app.e.TTAndroidObject;
import com.ss.android.article.base.feature.detail2.ArticleDetailWebPage;
import com.ss.android.newmedia.webview.BaseWebChromeClient;

import java.lang.ref.WeakReference;

public final class DetailWebChromeClient extends BaseWebChromeClient {
    private WeakReference<ArticleDetailWebPage> ref;

    public DetailWebChromeClient(Activity activity, ArticleDetailWebPage arg3) {
        super(activity);
        this.ref = new WeakReference(arg3);
    }

    public DetailWebChromeClient(Fragment fragment) {
        this(fragment, fragment instanceof ArticleDetailWebPage ? (ArticleDetailWebPage) fragment : null);

    }

    public DetailWebChromeClient(Fragment fragment, ArticleDetailWebPage arg3) {
        super(fragment);
        this.ref = new WeakReference(arg3);
    }

    public final void onConsoleMessage(String message, int line, String sourceID) {
        TTAndroidObject v0_2;
        if (Logger.debug()) {
            Logger.d("DetailActivity", message + " -- line " + line);
        }
        try {
            Object v0_1 = this.ref.get();
            if (v0_1 != null) {
                v0_2 = ((ArticleDetailWebPage) v0_1).getTTAndroidObject();
            } else {
                v0_2 = null;
            }
            if (v0_2 == null) {
                return;
            }
            v0_2.checkLogMsg(message);
        } catch (Exception v0) {
            v0.printStackTrace();
        }
    }

    public final boolean onConsoleMessage(ConsoleMessage consoleMessage) {
        this.ref.get();
        return super.onConsoleMessage(consoleMessage);
    }

    public final void onGeolocationPermissionsHidePrompt() {
        Object v0 = this.ref.get();
        TTAndroidObject ttAndroidObject = v0 != null ? ((ArticleDetailWebPage) v0).getTTAndroidObject() : null;
        if (ttAndroidObject != null) {
            ttAndroidObject.onGeolocationPermissionsHidePrompt();
        }
    }

    public final void onGeolocationPermissionsShowPrompt(String arg2, GeolocationPermissions.Callback arg3) {
        ArticleDetailWebPage v0 = this.ref.get();
        TTAndroidObject v0_1 = v0 != null ? ((ArticleDetailWebPage) v0).getTTAndroidObject() : null;
        if (v0_1 != null) {
            v0_1.onGeolocationPermissionsShowPrompt(arg2, arg3);
        }
    }

    public final void onHideCustomView() {
        Object v0 = this.ref.get();
        if (v0 != null) {
            ((ArticleDetailWebPage) v0).onHideCustomView();
        }
    }

    public final void onProgressChanged(WebView webView, int newProgress) {
        Object v0 = this.ref.get();
        if (v0 != null) {
            ((ArticleDetailWebPage) v0).onProgressChanged(webView, newProgress);
        }
    }

    public final void onSelectionStart(WebView arg1) {
    }

    public final void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
        ArticleDetailWebPage v0 = this.ref.get();
        if (v0 != null) {
            ((ArticleDetailWebPage) v0).onShowCustomView(view, customViewCallback);
        }
    }
}

